package report

import (
	"context"
	"git.mycaigou.com/gfyx/common/rpc_client"
	reportDto "git.mycaigou.com/gfyx/micro-gfyx-mp-api/http_server/dto/report"
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/infrastructure/common/constants"
	cluePb "git.mycaigou.com/gfyx/micro-gfyx-mp-api/proto/micro_gfyx_oppty_service_proto/micro-gfyx-oppty-service/clue"
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/service/clue/report"
)

type reportFollowRepository struct {
}

func NewReportFollowRepository() report.ReportFollowRepositoryIface {
	return &reportFollowRepository{}
}

func (r *reportFollowRepository) SaveFollowRecord(ctx context.Context, req *reportDto.SaveFollowRecordRequest) error {
	request := cluePb.SaveFollowRecordRequest{
		Data: &cluePb.FollowRecord{
			ReportId:       req.ReportId,
			FollowType:     req.FollowType,
			FollowStatus:   req.FollowStatus,
			FollowContent:  req.FollowContent,
			FollowUserName: req.FollowUserName,
			Province:       req.Province,
			ProvinceCode:   req.ProvinceCode,
			City:           req.City,
			CityCode:       req.CityCode,
			Address:        req.Address,
			Images:         req.Images,
		},
	}
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewReportServiceClient(conn)
	_, err = client.SaveFollowRecord(ctx, &request)
	if err != nil {
		return err
	}
	return nil
}

func (r *reportFollowRepository) GetFollowRecordList(ctx context.Context, reportId string, page int32, PageSize int32) (*cluePb.GetFollowRecordListResponse, error) {
	request := cluePb.GetFollowRecordListRequest{
		ReportId: reportId,
		Page:     page,
		PageSize: PageSize,
	}
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewReportServiceClient(conn)
	return client.GetFollowRecordList(ctx, &request)
}
